package com.eastidea.live.field.multiplechoice;

import net.sf.json.JSONObject;

import com.eastidea.live.entity.FrmInfMultipleChoice;
import com.eastidea.live.entity.FrmInfMultipleOptions;
import com.eastidea.live.entity.FrmUiForm;
import com.eastidea.live.ot.FieldOt;

public class MultipleChoiceOt {
	public static MultipleChoiceTo GenerateChoiceTo(FrmInfMultipleChoice po, FrmUiForm form) {
		Long id = form.getId() > 0? po.getId(): 0;
		
		MultipleChoiceTo to = new MultipleChoiceTo();
			
		to.setId(id); 
		to.setUid(po.getUid());
		
		to.setCode(po.getCode());
		to.setIsRequired(po.getIsRequired());
		to.setIndexx(po.getIndexx());
		to.setStatus(po.getStatus());
		
		to.setLegend(po.getLegend());
		return to;
	}

	public static MultipleChoiceOptionsTo GenerateOptionTo(
			FrmInfMultipleOptions po, MultipleChoiceTo choiceTo, FrmUiForm form) {
		Long id = form.getId() > 0? po.getId(): 0;
		
		MultipleChoiceOptionsTo to = new MultipleChoiceOptionsTo();
		to.setId(id);
		to.setUid(po.getUid());
		to.setPuid(choiceTo.getUid());
		
		to.setCode("choice_options");
		to.setIsRequired(po.getIsRequired());
		to.setIndexx(po.getIndexx());
		to.setStatus(po.getStatus());

		to.setLabel(po.getLabel());
		to.setValuee(po.getValuee());
		to.setIsChecked(po.getIsChecked());
		
		return to;
	}
	
	public static FrmInfMultipleChoice GenerateMultipleChoicePo(JSONObject obj) {
		FrmInfMultipleChoice po = new FrmInfMultipleChoice();
		FieldOt.setUiElementProperties(po, obj);
		po.setLegend(obj.getString("legend"));
		
		return po;
	}

	public static FrmInfMultipleOptions GenerateMultipleChoiceOptionsPo(
			JSONObject obj, FrmInfMultipleChoice choice) {
		FrmInfMultipleOptions po = new FrmInfMultipleOptions();
		FieldOt.setUiElementProperties(po, obj);
		po.setLabel(obj.getString("label"));
		po.setValuee(obj.getString("valuee"));
		po.setIsChecked(obj.getBoolean("isChecked"));
		
		po.setFrmInfMultipleChoice(choice);
		return po;
	}

}
